RAIS  3.2
C:/Projekte/RAIS/Specific Masks/EditDataRoles_New_Update2.aspx.cs
Go to the documentation of this file.
00001 
00028 using System;
00029 using System.Data;
00030 using System.Configuration;
00031 using System.Collections;
00032 using System.Collections.Generic;
00033 using System.Web;
00034 using System.Web.Security;
00035 using System.Web.UI;
00036 using System.Web.UI.WebControls;
00037 using System.Web.UI.WebControls.WebParts;
00038 using System.Web.UI.HtmlControls;
00039 
00040 using RAIS;
00041 using RAIS.Common.UserManagement;
00042 //using RAIS.ApplicationLogicLayer;
00043 
00044 using DataRoles = System.Collections.Generic.Dictionary<string, RAIS.Common.UserManagement.DataRole>;
00045 using DataRoleAttributes = System.Collections.Generic.Dictionary<string, RAIS.Common.UserManagement.DataRoleAttribute>;
00046 using Regions = System.Collections.Generic.Dictionary<string, RAIS.Common.UserManagement.Region>;
00047 using Districts = System.Collections.Generic.Dictionary<string, RAIS.Common.UserManagement.District>;
00048 using Facilities = System.Collections.Generic.Dictionary<string, RAIS.Common.UserManagement.Facility>;
00049 
00050 namespace RAIS.UI.SpecificMasks
00051 {
00055     public partial class EditDataRoles_New_Update2 : System.Web.UI.Page
00056     {
00057                 enum PageMode
00058                 {
00059                         viewRoles,
00060                         addRole,
00061                         editRole
00062                 };
00063                 //*********************************************************************
00064                 #region Event handlers
00065         protected void Page_PreLoad(object sender, EventArgs e)
00066         {
00067             RAIS.UI.Common.PageManagement.TrimTextBoxValues(this);
00068         }
00074         protected void Page_Load(object sender, EventArgs e)
00075         {
00076                         this.Response.Cache.SetNoStore();
00077                         if (this.CurrentUser == null)
00078                                 UI.Common.AccessManagement.SignOut(this);
00079 
00080                         this.LBLresult.Text = string.Empty;
00081 
00082                         if (!this.IsPostBack)
00083                         {
00084                 UI.Common.Localisation.TranslateGridViewHeader(this.GVfpermissions, this.ToString(), RAIS.Common.Constants.DEFAULT_LANGUAGE, this.CurrentUser.Language);
00085                 this.BTNdelete.Attributes.Add("onclick", string.Format("javascript: return confirm('{0}');", RAIS.Common.Messages.DELETE_QUESTION_DATA_ROLE.Replace("'", "\\'")));
00086                 this.LBLadmin.ForeColor = RAIS.UI.Common.Constants.COLOR_OF_MENU_BAR_TEXT_HIGHLIGHT;
00087                 this.LBLusernameNoTranslation.Text = this.CurrentUser.Name;
00088                                 this.CurrentPageMode = PageMode.viewRoles;
00089 
00090                                 UI.Common.UserManagement.InitializeDataRolesListBox(this.LBdmrolename, this.SavedDataRoleSelection);
00091                                 this.ShowRole();
00092                                 UI.Common.PageManagement.InitializePage(this, this.TreeView1);
00093 //                              this.LBTNmessagebox.Visible = !(this.CurrentUser.FunctionalRole.Type == FunctionRole.FunctionRoleType.Guest);
00094                         }
00095             UI.Common.PageManagement.InitHelpMainMenu(LBTNdefault);
00096                 }
00102                 protected void Page_Init(object sender, EventArgs e)
00103         {
00104             Common.PageManagement.SetScrolableListBox(LBdmrolename, this, true);
00105         }
00116                 protected void LBdmrolename_SelectedIndexChanged(object sender, EventArgs e)
00117                 {
00118                         this.SavedDataRoleSelection = this.LBdmrolename.SelectedValue;
00119                         this.GVfpermissions.SelectedIndex = -1;
00120                         this.EnableDisableControls();
00121                         this.ShowRole();
00122                 }
00130                 protected void DDLdmregion_SelectedIndexChanged(object sender, EventArgs e)
00131                 {
00132                         this.DDLdmdistrict.Items.Clear();
00133                         this.DDLdmfacility.Items.Clear();
00134 
00135                         //UI.Common.UserManagement.InitializeDistrictsList(this.DDLdmdistrict,
00136                         //                                                    this.DDLdmregion.SelectedValue);
00137                         UI.Common.UserManagement.InitializeDistrictsListWithEmptyRow(this.DDLdmdistrict,
00138                                                                                                                                 this.DDLdmregion.SelectedValue);
00139 
00140                         UI.Common.UserManagement.InitializeFacilitiesList(this.DDLdmfacility,
00141                                                                                                                                 this.DDLdmregion.SelectedValue,
00142                                                                                                                                 this.DDLdmdistrict.SelectedValue);
00143                 }
00151                 protected void DDLdmdistrict_SelectedIndexChanged(object sender, EventArgs e)
00152                 {
00153                         this.DDLdmfacility.Items.Clear();
00154                         UI.Common.UserManagement.InitializeFacilitiesList(this.DDLdmfacility,
00155                                                                                                                                 this.DDLdmregion.SelectedValue,
00156                                                                                                                                 this.DDLdmdistrict.SelectedValue);
00157                 }
00164                 protected void BTNadd_Click(object sender, EventArgs e)
00165                 {
00166                         this.CurrentPageMode = PageMode.addRole;
00167                         this.InitializeEditControls();
00168                 }
00175                 protected void BTNedit_Click(object sender, EventArgs e)
00176                 {
00177                         this.CurrentPageMode = PageMode.editRole;
00178                         this.InitializeEditControls();
00179                 }
00186                 protected void BTNdelete_Click(object sender, EventArgs e)
00187                 {
00188                         bool success = true;
00189                         success = this.RemoveDataRoleAttribute();
00190                         if (success)
00191                                 this.SaveRole();
00192                 }
00199                 protected void BTNdiscard_Click(object sender, EventArgs e)
00200                 {
00201                         this.CurrentPageMode = PageMode.viewRoles;
00202                 }
00209                 protected void BTNapply_Click(object sender, EventArgs e)
00210                 {
00211                         bool success = true;
00212                         if (this.CurrentPageMode == PageMode.editRole)
00213                         {
00214                                 success = this.RemoveDataRoleAttribute();
00215                         }
00216                         if (success)
00217                                 success = this.AddDataRoleAttribute();
00218                         if (success)
00219                                 this.SaveRole();
00220                 }
00227                 protected void GVfpermissions_RowCommand(object sender, GridViewCommandEventArgs e)
00228                 {
00229                         if (e.CommandName.Equals("Select"))
00230                         {
00231                                 int rowIndex = Convert.ToInt32(e.CommandArgument);
00232                                 this.GVfpermissions.SelectedIndex = rowIndex;
00233                                 this.EnableDisableControls();
00234                         }
00235                 }
00242                 protected void TreeView1_SelectedNodeChanged(object sender, EventArgs e)
00243         {
00244             UI.Common.UserManagement.ProcessTreeViewOnRedirect(this.TreeView1);
00245         }
00252         protected void LBTNlogout_Click(object sender, EventArgs e)
00253         {
00254             UI.Common.AccessManagement.SignOut(this);
00255         }
00256         #endregion
00257                 //*********************************************************************
00258                 #region Private helper methods
00259 
00265                 void ShowRole()
00266                 {
00267                         if (this.SelectedRole != null)
00268                         {
00269                                 this.InitializeGridView();
00270                         }
00271                 }
00275                 protected void InitializeGridView()
00276                 {
00277                         this.GVfpermissions.DataSource = this.SelectedRole.Attributes.Values;
00278                         this.GVfpermissions.DataBind();
00279                 }
00283                 private void InitializeEditControls()
00284                 {
00285                         //UI.Common.UserManagement.InitializeRegionsList(this.DDLdmregion, this.SelectedRole);
00286                         UI.Common.UserManagement.InitializeRegionsListWithEmptyRow(this.DDLdmregion, this.SelectedRole);
00287                         this.SetRegionSelection(this.SelectedRoleAttribute);
00288 
00289                         //UI.Common.UserManagement.InitializeDistrictsList(this.DDLdmdistrict,
00290                         //                                                        this.SelectedRegion.Name);
00291                         UI.Common.UserManagement.InitializeDistrictsListWithEmptyRow(this.DDLdmdistrict,
00292                                                                                                                                 this.DDLdmregion.SelectedValue);
00293                         this.SetDistrictSelection(this.SelectedRoleAttribute);
00294 
00295                         UI.Common.UserManagement.InitializeFacilitiesList(this.DDLdmfacility,
00296                                                                                                                                         this.SelectedRegion.Name,
00297                                                                                                                                         this.SelectedDistrict.Name);
00298                         this.SetFacilitySelection(this.SelectedRoleAttribute);
00299                 }
00303                 private void EnableDisableControls()
00304                 {
00305                         this.LBdma.Enabled = this.CurrentPageMode == PageMode.viewRoles;
00306                         this.LBdmrolename.Enabled = (this.CurrentPageMode == PageMode.viewRoles);
00307                         this.GVfpermissions.Enabled = (this.CurrentPageMode == PageMode.viewRoles);
00308                         this.BTNadd.Enabled = (this.CurrentPageMode == PageMode.viewRoles);
00309                         this.BTNedit.Enabled = (this.CurrentPageMode == PageMode.viewRoles) && (this.SelectedRoleAttribute != null);
00310                         this.BTNdelete.Enabled = (this.CurrentPageMode == PageMode.viewRoles) && (this.SelectedRoleAttribute != null);
00311                         this.BTNsave.Enabled = !(this.CurrentPageMode == PageMode.viewRoles);
00312                         this.BTNdiscard.Enabled = !(this.CurrentPageMode == PageMode.viewRoles);
00313                         this.FSattributes.Visible = !(this.CurrentPageMode == PageMode.viewRoles);
00314 
00315                         UI.Common.UserManagement.EnableCommonControls(this, (this.CurrentPageMode == PageMode.viewRoles));
00316                 }
00320                 private bool AddDataRoleAttribute()
00321                 {
00322                         bool success = true;
00323                         DataRole selectedRole = this.SelectedRole;
00324                         if (selectedRole != null)
00325                         {
00326                                 DataRoleAttribute dataAttribute = new DataRoleAttribute();
00327                                 dataAttribute.Region = this.SelectedRegion;
00328                                 dataAttribute.District = this.SelectedDistrict;
00329                                 dataAttribute.Facility = this.SelectedFacility;
00330 
00331                                 string returnMessage = RAIS.Common.Messages.MODIFICATION_PRESS_SAVE;
00332 
00333                                 success = this.ValidateNewDataRoleAttribute(dataAttribute, ref returnMessage);
00334                                 if (success)
00335                                 {
00336                                         this.CurrentPageMode = PageMode.viewRoles;
00337                                         success = selectedRole.AddAttribute(dataAttribute, ref returnMessage);
00338                                         if (success)
00339                                                 this.Modified = true;
00340 
00341                                 }
00342                                 RAIS.UI.Common.MessageDisplay.DisplayReturnMessage(this.LBLresult,
00343                                                                                                                                         returnMessage,
00344                                                                                                                                         success);
00345                         }
00346                         return success;
00347                 }
00351                 private bool RemoveDataRoleAttribute()
00352                 {
00353                         bool success = false;
00354                         DataRole selectedRole = this.SelectedRole;
00355                         if (selectedRole != null)
00356                         {
00357                                 DataRoleAttribute attribute = this.SelectedRoleAttribute;
00358 
00359                                 string returnMessage = RAIS.Common.Messages.MODIFICATION_PRESS_SAVE;
00360                                 success = selectedRole.RemoveAttribute(attribute, ref returnMessage);
00361                                 this.EnableDisableControls();
00362 
00363                                 RAIS.UI.Common.MessageDisplay.DisplayReturnMessage(this.LBLresult, returnMessage, success);
00364                         }
00365                         return success;
00366                 }
00371                 private bool SaveRole()
00372                 {
00373                         string returnMessage = string.Empty;
00374                         bool success = true;
00375 
00376                         if (!this.Modified)
00377                         {
00378                                 returnMessage = RAIS.Common.Messages.DATA_ROLE_NO_MODIFICATION;
00379                                 success = false;
00380                         }
00381                         else
00382                         {
00383                                 success = ApplicationLogicLayer.UserManagement.SaveDataRole(this.SelectedRole, ref returnMessage);
00384                                 if (success)
00385                                 {
00386                                         this.CurrentPageMode = PageMode.viewRoles;
00387                                         this.Modified = false;
00388 
00389                                         this.InitializeGridView();
00390                                 }
00391                         }
00392                         RAIS.UI.Common.MessageDisplay.DisplayReturnMessage(this.LBLresult,
00393                                                                                                                                 returnMessage,
00394                                                                                                                                 success);
00395                         return success;
00396                 }
00405                 bool ValidateNewDataRoleAttribute(DataRoleAttribute newDataRoleAttribute, ref string returnMessage)
00406                 {
00407                         DataRole dataRole = this.SelectedRole;
00408                         if (dataRole == null)
00409                         {
00410                                 returnMessage = RAIS.Common.Messages.DATA_ROLE_DOES_NOT_EXIST;
00411                                 return false;
00412                         }
00413                         else
00414                         {
00415                                 return dataRole.ValidateNewAttribute(newDataRoleAttribute, ref returnMessage);
00416                         }
00417                 }
00423                 private void SetRegionSelection(DataRoleAttribute roleAttribute)
00424                 {
00425                         if (roleAttribute != null
00426                                 && this.DDLdmregion.Items.Contains(new ListItem(roleAttribute.Region.Name)))
00427                         {
00428                                 this.DDLdmregion.SelectedValue = roleAttribute.Region.Name;
00429                         }
00430                 }
00436                 private void SetDistrictSelection(DataRoleAttribute roleAttribute)
00437                 {
00438                         if (roleAttribute != null
00439                                 && this.DDLdmdistrict.Items.Contains(new ListItem(roleAttribute.District.Name)))
00440                         {
00441                                 this.DDLdmdistrict.SelectedValue = roleAttribute.District.Name;
00442                         }
00443                 }
00449                 private void SetFacilitySelection(DataRoleAttribute roleAttribute)
00450                 {
00451                         if (roleAttribute != null
00452                                 && this.DDLdmfacility.Items.Contains(new ListItem(roleAttribute.Facility.Name)))
00453                         {
00454                                 this.DDLdmfacility.SelectedValue = roleAttribute.Facility.Name;
00455                         }
00456                 }
00457                 #endregion
00458                 //*********************************************************************
00459                 #region Properties
00460 
00463                 private DataRole SelectedRole
00464                 {
00465                         get
00466                         {
00467                                 DataRole dataRole = null;
00468 
00469                                 if (this.LBdmrolename.SelectedIndex != -1)
00470                                 {
00471                                         DataRoles dataRoles = (DataRoles)this.Session[RAIS.UI.Common.Constants.DATA_ROLES_TAG];
00472                                         if (dataRoles.ContainsKey(this.LBdmrolename.SelectedValue))
00473                                                 dataRole = dataRoles[this.LBdmrolename.SelectedValue];
00474                                 }
00475 
00476                                 return dataRole;
00477                         }
00478                 }
00482                 private Region SelectedRegion
00483                 {
00484                         get
00485                         {
00486                                 Regions regions = (Regions)this.Session[RAIS.UI.Common.Constants.REGIONS_TAG];
00487                                 if (regions != null)
00488                                         if (this.DDLdmregion.SelectedValue == string.Empty)
00489                                                 return new Region();
00490                                         else
00491                                                 return regions[this.DDLdmregion.SelectedValue];
00492                                 else
00493                                         return null;
00494                         }
00495                 }
00499                 private District SelectedDistrict
00500                 {
00501                         get
00502                         {
00503                                 Districts districts = ApplicationLogicLayer.UserManagement.GetDistrictsByRegion(this.SelectedRegion);
00504                                 if (districts != null)
00505                                         if (this.DDLdmdistrict.SelectedValue == string.Empty)
00506                                                 return new District();
00507                                         else
00508                                                 return districts[this.DDLdmdistrict.SelectedValue];
00509                                 else
00510                                         return null;
00511                         }
00512                 }
00516                 private Facility SelectedFacility
00517                 {
00518                         get
00519                         {
00520                                 Region selectedRegion = this.SelectedRegion;
00521                                 District selectedDistrict = this.SelectedDistrict;
00522                                 Facilities facilities = ApplicationLogicLayer.UserManagement.GetFacilitiesByRegionAndDistrict(selectedRegion, selectedDistrict);
00523                 if (facilities != null)
00524                     if (this.DDLdmfacility.SelectedValue == string.Empty)
00525                         return new Facility();
00526                     else
00527                         return facilities[this.DDLdmfacility.SelectedValue];
00528                 else
00529                     return null;
00530                         }
00531                 }
00535                 private DataRoleAttribute SelectedRoleAttribute
00536                 {
00537                         get
00538                         {
00539                                 if (this.SelectedRole != null)
00540                                         return this.SelectedRole.GetAttributeByIndex(GVfpermissions.SelectedIndex);
00541                                 else
00542                                         return null;
00543                         }
00544                 }
00548                 PageMode CurrentPageMode
00549                 {
00550                         get
00551                         {
00552                                 if (this.Session[UI.Common.Constants.DATA_ROLE_EDIT_MODE_TAG] != null)
00553                                 {
00554                                         return (PageMode)this.Session[UI.Common.Constants.DATA_ROLE_EDIT_MODE_TAG];
00555                                 }
00556                                 else
00557                                         return PageMode.viewRoles;
00558                         }
00559                         set
00560                         {
00561                                 string message;
00562                                 switch (value)
00563                                 {
00564                                         case PageMode.addRole: message = RAIS.UI.Common.Constants.ADDING_NEW_DATA_ROLE; break;
00565                                         case PageMode.editRole: message = RAIS.UI.Common.Constants.EDITTING_EXISTING_DATA_ROLE; break;
00566 
00567                                         default:
00568                                                 this.Session[RAIS.UI.Common.Constants.DATA_ROLE_TEMPORARY_TAG] = null;
00569                                                 message = string.Empty;
00570                                                 break;
00571                                 }
00572                                 RAIS.UI.Common.MessageDisplay.DisplayReturnMessage(this.LBLresult, message, true);
00573                                 this.Session[UI.Common.Constants.DATA_ROLE_EDIT_MODE_TAG] = value;
00574                                 this.EnableDisableControls();
00575                         }
00576                 }
00580                 bool Modified
00581                 {
00582                         get
00583                         {
00584                                 if (this.SelectedRole != null)
00585                                         return this.SelectedRole.Modified;
00586                                 else
00587                                         return false;
00588                         }
00589                         set
00590                         {
00591                                 if (this.SelectedRole != null)
00592                                         this.SelectedRole.Modified = value;
00593                         }
00594                 }
00598         protected UserData CurrentUser
00599         {
00600             get { return (UserData)this.Session[UI.Common.Constants.CURRENT_USER_TAG]; }
00601         }
00605                 private string SavedDataRoleSelection
00606                 {
00607                         get
00608                         {
00609                                 if (this.Session[RAIS.UI.Common.Constants.DATA_ROLE_SAVED_SELECTION_TAG] != null)
00610                                         return this.Session[RAIS.UI.Common.Constants.DATA_ROLE_SAVED_SELECTION_TAG].ToString();
00611                                 else
00612                                         return string.Empty;
00613                         }
00614                         set
00615                         {
00616                                 this.Session[RAIS.UI.Common.Constants.DATA_ROLE_SAVED_SELECTION_TAG] = value;
00617                         }
00618                 }
00619         #endregion Properties
00620     }
00621 }